﻿/*
 * zcmd_unittest.cxx
 *
 *  Created on: 2015年3月4日
 *      Author: Fifi Lyu
 */

#include <gtest/gtest.h>
#include "zpsoe/zcmd.h"
#include "zpsoe/zfilesys.h"

using zpsoe::zcmd::get_exit_status_of_cmd;
using zpsoe::zcmd::get_output_of_cmd;
using zpsoe::zfilesys::is_exist;

TEST(ZcmdTest, get_exit_status_of_cmd) {
    string cmd_("");
    bool ret_ = false;

    if (is_exist("zcmd_test")) {
        cmd_ = "rmdir zcmd_test";
        ret_ = get_exit_status_of_cmd(cmd_);
        EXPECT_TRUE(ret_);
    }

    cmd_ = "mkdir zcmd_test";
    ret_ = get_exit_status_of_cmd(cmd_);
    EXPECT_TRUE(ret_);

    cmd_ = "rmdir zcmd_test";
    ret_ = get_exit_status_of_cmd(cmd_);
    EXPECT_TRUE(ret_);
}

TEST(ZcmdTest, get_output_of_cmd) {
    string cmd_("echo testing");
    string ret_(get_output_of_cmd(cmd_));
    const string expected_("testing\n");
    EXPECT_STREQ(expected_.c_str(), ret_.c_str());
}


//TODO windows execute_cmd_with_sub_proc
